package DataBase;

import java.sql.*;

public class myDB {

    String dataBaseName;
    String USER="root";
    String URL;
    String NAME="123Godlikeme321!";
    Connection connection;
    Statement statement;

    PreparedStatement preparedStatement;

    public myDB(){};

    public myDB(String dataBaseName){
        try {this.dataBaseName=dataBaseName;
            URL= "jdbc:mysql://localhost:3306/"+dataBaseName+"?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8";
            Class.forName("com.mysql.cj.jdbc.Driver");
            connection= DriverManager.getConnection(URL,USER,NAME);
            statement=connection.createStatement();
        } catch (ClassNotFoundException | SQLException e) {
            e.printStackTrace();
        }
    }
    public myDB(String dataBaseName,String USER){
        try {this.dataBaseName=dataBaseName;
            URL="jdbc:mysql://localhost:3306/"+dataBaseName+"?useSSL=false&serverTimezone=UTC";
            Class.forName("com.mysql.cj.jdbc.Driver");
            connection= DriverManager.getConnection(URL,USER,NAME);
            statement=connection.createStatement();
        } catch (ClassNotFoundException | SQLException e) {
            e.printStackTrace();
        }
    }

    public void close(){
        try {
            this.statement.close();
            this.connection.close();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }

    public Connection getConnection() {
        return connection;
    }

    public PreparedStatement getPreparedStatement() {
        return preparedStatement;
    }

    public Statement getStatement() {
        return statement;
    }


}